package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/07 15:12
 **/
public class Day5_3_Offer68_LowestCommonAncestor {
    class Solution {
        public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
            if(root.val == p.val) return root;
            if(root.val == q.val) return root;
            if(root.val > p.val && root.val > q.val)
                return lowestCommonAncestor(root.left, p, q);
            else if(root.val < p.val && root.val < q.val)
                return lowestCommonAncestor(root.right, p , q);
            else return root;
        }
    }
}